package kr.co.handysoft.common.vo;

import java.util.HashMap;
import java.util.Map;

public class DatabaseServerInformation extends ServerInformation {

	private DatabaseInformation dbInfo;
	private Map<String, String> queryCollection = new HashMap<String, String>();
	
	public DatabaseServerInformation() {
		super();
	}

	public DatabaseServerInformation(String id, String ip, String port, String usedCheck, String desc) {
		super(id, ip, port, usedCheck, desc);		
	}

	public void setDataBaseInformation(String id, String passwd, String database, String sid, int idleCnt, int maxConn, String url){
		this.dbInfo = new DatabaseInformation(id, passwd, database, sid, idleCnt, maxConn, url);
	}
	
	public void setDatabaseInformation(DatabaseInformation dbInfo) {
		this.dbInfo = dbInfo;
	}

	public DatabaseInformation getDatabaseInformation() {
		return dbInfo;
	}
	
	public void addQuery(String query_id, String query_value){
		System.out.printf("query : %s, %s \n", query_id, query_value);
		this.queryCollection.put(query_id, query_value);
	}
	
	public String getQuery(int query_id){
		return getQuery(query_id+"");
	}
	
	public String getQuery(String query_id){
		return this.queryCollection.get(query_id);
	}
	
	public void loadData(){
		for (int i=0; i<6; i++){
			getLevelData(i+"");
		}
	}
	
	public void getLevelData(String levelKey){
		String queryString = queryCollection.get(levelKey);
		dbInfo.getData(Integer.parseInt(levelKey), "vehicleNumber", queryString); 
	}
	
	public void addLevelData(String levelKey, Vehicle vehicle){
		String queryString = queryCollection.get(levelKey);
		dbInfo.addData(Integer.parseInt(levelKey), vehicle, queryString); 
	}
	
	public void delLevelData(String levelKey, Vehicle vehicle){
		String queryString = queryCollection.get(levelKey);
		dbInfo.delData(Integer.parseInt(levelKey), vehicle, queryString); 
	}
}
